package cn.iocoder.yudao.module.trade.controller.admin.giftcard;

import cn.iocoder.yudao.module.trade.dal.dataobject.giftcard.GiftWxCardDO;
import cn.iocoder.yudao.module.trade.service.giftcard.GiftWxCardService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.trade.controller.admin.giftcard.vo.*;


@Tag(name = "管理后台 - 微信卡劵")
@RestController
@RequestMapping("/gift/wx-card")
@Validated
public class WxCardController {

    @Resource
    private GiftWxCardService wxCardService;

    @PostMapping("/create")
    @Operation(summary = "创建微信卡劵")
    public CommonResult<Long> createWxCard(@Valid @RequestBody WxCardSaveReqVO createReqVO) {
        return success(wxCardService.createWxCard(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新微信卡劵")
    public CommonResult<Boolean> updateWxCard(@Valid @RequestBody WxCardSaveReqVO updateReqVO) {
        wxCardService.updateWxCard(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除微信卡劵")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteWxCard(@RequestParam("id") Long id) {
        wxCardService.deleteWxCard(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得微信卡劵")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<WxCardRespVO> getWxCard(@RequestParam("id") Long id) {
        GiftWxCardDO wxCard = wxCardService.getWxCard(id);
        return success(BeanUtils.toBean(wxCard, WxCardRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得微信卡劵分页")
    public CommonResult<PageResult<WxCardRespVO>> getWxCardPage(@Valid WxCardPageReqVO pageReqVO) {
        PageResult<GiftWxCardDO> pageResult = wxCardService.getWxCardPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WxCardRespVO.class));
    }


}